lib/wasm: eliminate global namespace pollution in wasm_exec.js #98
+65
−69
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The wasm_exec.js file was unnecessarily polluting the global namespace
by adding fs, process, and path to globalThis. These variables are only
used within the importObject functions and can be captured via closure
scope instead.
Changes:
The IIFE wrapper already provides closure scope, so these variables
don't need to be global. WebAssembly modules can only access what's
in the importObject, and the functions in importObject access these
variables through normal JavaScript scope resolution.
Only globalThis.Go remains global as it's the documented public API
that user code needs to instantiate.
This change:
🔄 This is a mirror of upstream PR golang#75762